package com.sino.tb.adminiPunish;

import java.sql.*;
import java.util.*;
import xpubbean.Db.*;

public class TempDM {
	Conn conn = null;
	Connection connection = null;
	Statement stmt = null;
	public TempDM() {
		try {
			conn = new Conn();
			connection = conn.getConnection();
			stmt = connection.createStatement();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	/**
	 *
	 * @param sql String
	 * @throws Exception
	 * @return AbstractList
	 */
	public java.util.AbstractList Select_Data(String sql) throws Exception {
		ArrayList Data_list = new ArrayList();

		ResultSet rs = null;
		try {
			rs = stmt.executeQuery(sql);
			ResultSetMetaData rsmd = rs.getMetaData();
			int cols = rsmd.getColumnCount();
			int i = 0;
			while (rs.next() != false) {
				ArrayList arr_Row = new ArrayList();
				for (i = 1; i <= cols; ++i) {
					if (rs.getString(i) == null) {
						arr_Row.add("");
					} else {
						arr_Row.add(rs.getString(i));
					}
				}
				Data_list.add(arr_Row);
			}
			if (rs != null) {
				rs.close();
				rs = null;
			}
		} catch (SQLException sqle) {
			throw new SQLException("Select Data SQL exception: " +
								   sqle.getMessage());
		} catch (Exception e) {
			throw new Exception("System e exception: " + e.getMessage());
		} finally {
			try {
				if (rs != null) {
					rs.close();
				}
			} catch (Exception e) {
				throw new Exception("rs close exception: " + e.getMessage());
			}

//			try {
//				if (stmt != null) {
//					stmt.close();
//				}
//			} catch (Exception e) {
//				throw new Exception("stmt close exception: " + e.getMessage());
//			}

		}
		return Data_list;
	}

	public void close() throws Exception {
		if (this.stmt != null) {
			this.stmt.close();
			this.stmt = null;
		}
		if (this.connection != null && !this.connection.isClosed()) {
			this.connection.close();
			this.connection = null;
		}
	}

}
